package ghostbanlistd;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
	public static String BNGLIST_VERSION = "bnglist 0 (http://code.google.com/p/bnglist/)";
	public static File logTarget = null;
	public static boolean DEBUG = true;
	
	public static void main(String args[]) {
		println(BNGLIST_VERSION);
		String propertiesFile = "bnglist.cfg";
		
		if(args.length >= 1) {
			propertiesFile = args[0];
		}
		
		boolean result = Config.init(propertiesFile);
		if(!result) return; //fatal error
		
		String logTargetStr;
		if((logTargetStr = Config.getString("ban_log", null)) != null) {
			logTarget = new File(logTargetStr);
			println("Logging to " + logTarget.getAbsolutePath());
		}
		
		println("[Main] Starting up");
	}
	
	public static void println(String message) {
		System.out.println(message);
		
		//output to file
		if(logTarget != null) {
			try {
				PrintWriter out = new PrintWriter(new FileWriter(logTarget));
				out.println(message);
				out.close();
			} catch(IOException ioe) {
				System.out.println("[Main] Output to " + logTarget + " failed (disabling): " + ioe.getLocalizedMessage());
				logTarget = null;
			}
		}
	}
}